<template>
  <div class="customerStatistics">
    <div class="title">功能使用<span class="icon">指标说明</span>
    </div>
    <ul class="tabList">
      <li :class="active==0?`active`:``" @click="getActive(0)">高级群发</li>
      <li :class="active==1?`active`:``" @click="getActive(1)">极速群发</li>
      <li :class="active==2?`active`:``" @click="getActive(2)">客户朋友圈</li>
      <li :class="active==3?`active`:``" @click="getActive(3)">加群好友</li>
      <li :class="active==4?`active`:``" @click="getActive(4)">SOP</li>
      <li :class="active==5?`active`:``" @click="getActive(5)">智能应答</li>
    </ul>
    <div class="formGroup">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="130px" class="">
        <el-form-item prop="userName2">
          <el-select v-model="queryParams.userName2" size="small" filterable placeholder="全部账号" @change="handleQuery" style="width: 150px;">
            <el-option
              v-for="item in userList"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="userName2">
          <el-select v-model="queryParams.userName2" size="small" filterable placeholder="全部分组" @change="handleQuery" style="width: 150px;">
            <el-option
              v-for="item in userList"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="userName2">
          <multipleWeChat :options="options" @getValue="getValue" :placeholderText="`全部企微号`"></multipleWeChat>
        </el-form-item>
        <el-form-item prop="userName2" v-if="active !=5">
          <div class="time-big">
            <ul class="timeType">
              <li :class="selectedRange=='today'?`active`:``" @click="getTime('today')">今天</li>
              <li :class="selectedRange=='yesterday'?`active`:``" @click="getTime('yesterday')">昨天</li>
              <li :class="selectedRange=='last7Days'?`active`:``" @click="getTime('last7Days')">近7天</li>
              <li :class="selectedRange=='last15Days'?`active`:``" @click="getTime('last15Days')">近15天</li>
              <li :class="selectedRange=='last30Days'?`active`:``" @click="getTime('last30Days')">近30天</li>
            </ul>
            <el-date-picker
              size="small"
              v-model="timeRange"
              style="width: 240px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </div>

        </el-form-item>
        <el-form-item prop="userName2" v-if="active ==5">
          <div class="search">
            <el-input v-model="queryParams.userName1" size="small" placeholder="搜索问题/id" clearable/>
            <el-button icon="el-icon-search" size="small" @click="handleQuery"></el-button>
          </div>
        </el-form-item>
        <el-form-item prop="userName2" v-if="active ==5">
          <div class="search">
            <el-input v-model="queryParams.userName1" size="small" placeholder="搜索方案/id" clearable/>
            <el-button icon="el-icon-search" size="small" @click="handleQuery"></el-button>
          </div>
        </el-form-item>
        <el-form-item prop="userName2" v-if="active ==5">
          <div class="search">
            <el-input v-model="queryParams.userName1" size="small" placeholder="搜索来源问题/id" clearable/>
            <el-button icon="el-icon-search" size="small" @click="handleQuery"></el-button>
          </div>
        </el-form-item>
        <el-form-item prop="userName2" v-if="active ==5">
          <div class="search">
            <el-input v-model="queryParams.userName1" size="small" placeholder="搜索来源方案/id" clearable/>
            <el-button icon="el-icon-search" size="small" @click="handleQuery"></el-button>
          </div>
        </el-form-item>
      </el-form>

      <el-button  plain size="small">{{ active == 5 ? `生成汇总数据并导出` : `导出数据`}}</el-button>
    </div>
<!--    高级群发-->
    <heightSending v-if="active==0"></heightSending>
<!--    极速群发-->
    <rapidSending v-if="active==1"></rapidSending>
<!--    客户朋友圈-->
    <CustomerMoments v-if="active==2"></CustomerMoments>
<!--    加群好友-->
    <addGroupFriends v-if="active==3"></addGroupFriends>
    <!-- SOP-->
    <SOP v-if="active==4"></SOP>
<!--    智能应答-->
   <IntelligentResponse v-if="active==5"></IntelligentResponse>
  </div>
</template>
<script>
import {listUser} from "@/api/system/user";
import {getTime} from "@/utils";

export default {
  name: "FunctionUsage",
  components: {
    'multipleWeChat': () => import('@/views/components/multipleWeChat.vue'),
    'heightSending': () => import('./heightSending.vue'),
     'rapidSending': () => import('./rapidSending.vue'),
    'CustomerMoments': () => import('./CustomerMoments.vue'),
    'addGroupFriends': () => import('./addGroupFriends.vue'),
    'SOP': () => import('./SOP.vue'),
    'IntelligentResponse': () => import('./IntelligentResponse.vue'),
  },
  data() {
    return {
      active:0,
      queryParams: {},
      timeRange:[],
      selectedRange: 'today',
      options: [{
        value: 1,
        label: '小红',
        WeChatNum: 2,
        WeChatName: '智行',
      }, {
        value: 2,
        label: '小军',
        WeChatNum: 1,
        WeChatName: '锐行',
      }, {
        value: 3,
        label: '小李',
        WeChatNum: 1,
        WeChatName: '锐行',
      }],
      userList: [
        {
          value: '1',
          label: '员工1'
        }, {
          value: '2',
          label: '员工2'
        }
      ],
    }
  },
  watch: {},
  computed: {
  },
  created() {
    //this.getList();

  },
  methods: {
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      listUser(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.tableDataList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    getActive(index){
      this.active=index;
    },
    getTime(type) {
      this.selectedRange = type;
      setTimeout(() => {
        console.log('时间范围', this.dateRange);
        this.timeRange = [];
        this.timeRange = [this.fiterTime(this.dateRange[0]), this.fiterTime(this.dateRange[1])];
        console.log('转化时间', this.timeRange);
      }, 0)
    },
    fiterTime(value) {
      if (!value) return '';
      const date = new Date(value);
      const year = date.getFullYear();
      const month = (date.getMonth() + 1).toString().padStart(2, '0');
      const day = date.getDate().toString().padStart(2, '0');
      return `${year}-${month}-${day}`;
    },
    getValue(obj){
      console.log('获取行',obj);
    },
  },

}
</script>


<style scoped lang="scss">
.title {
  display: flex;
  align-items: center;
  padding: 16px 0 0;
  font-weight: bold;
  font-size: 16px;
  margin-bottom:15px;
  position: relative;

  .icon {
    font-size: 12px;
    font-weight: 400;
    color: #3070ff;
    margin-left: 10px;
  }
  .time {
    position: absolute;
    right: 0px;
    top: 10px;
    color: #8C8C8C;
    font-size: 12px;
    font-weight: 400;
  }
}
.tabList {
  height: 40px;
  display: flex;
  align-items: center;
  margin-bottom: 10px;
  li {
    border: 1px solid #eee;
    padding: 0px 20px;
    list-style: none;
    height: 32px;
    display: flex;
    align-items: center;
    cursor: pointer;
    &.active {
      color: #3070ff;
      background: #fff;
      border-color: #3070ff;
    }
  }
  .tips{
    margin-left: 10px;
  }
}
.tooltipContent {
  width: 500px;
  p {
    line-height: 30px;
    padding: 0px;
    margin: 0px;
  }
  .bottom-center {
    margin-top: 50px;
  }
}
.time-big {
  display: flex;
  align-items: center;
}
.timeType {
  display: flex;
  align-items: center;
  margin-right: 10px;

  li {
    border: 1px solid #eee;
    height: 32px;
    margin: 0;
    padding: 0 15px;
    list-style: none;
    cursor: pointer;

    &.active {
      border-color: #2d8cf0;
      color: #2d8cf0;
    }
  }
}
.formGroup {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  width: 100%;
}
.search {
  display: flex;

  ::v-deep.el-input__inner {
    border-right: none !important;
    border-radius: 4px 0px 0px 0px;
  }

  ::v-deep .el-button--default {
    border-radius: 0px 4px 4px 0px;
    padding: 0px 10px;
  }
}
::v-deep .el-form-item {
  margin-bottom: 5px !important;
}
</style>
